# 项目:
# 文件: acaction
# 作者: Yang
# 日期: 2025/5/21 16:33
# coding:utf-8

import time
from time import sleep

from selenium.webdriver import ActionChains
from pytestdemo.tools import Util,UIAction

class Question_bank_management:

    element_info = None

    #单击单选题按钮
    @classmethod
    def click_single_choice_button(cls,driver):
        single_choice_button = driver.find_element(*eval(cls.element_info['single_choice_button']))
        single_choice_button.click()

    #选则方向
    @classmethod
    def select_scb_way(cls,driver):
        scb_way = driver.find_element(*eval(cls.element_info['scb_way']))
        UIAction.select_random_first(scb_way)

    #选择阶段
    @classmethod
    def select_scb_stage(cls,driver):
        scb_stage = driver.find_element(*eval(cls.element_info['scb_stage']))
        UIAction.select_random_first(scb_stage)

    #选择课程
    @classmethod
    def select_scb_class(cls,driver):
        scb_class = driver.find_element(*eval(cls.element_info['scb_class']))
        UIAction.select_random_first(scb_class)

    #填写题干
    @classmethod
    def input_topic(cls,driver,data):
        topic = driver.find_element(*eval(cls.element_info['topic']))
        UIAction.write(topic,data['topic'])

    #点击新增选项
    @classmethod
    def click_add_option(cls,driver):
        add_option = driver.find_element(*eval(cls.element_info['add_option']))
        add_option.click()
        sleep(2)

    #点击删除选项
    @classmethod
    def click_delete_option(cls,driver):
        delete_option = driver.find_element(*eval(cls.element_info['delete_option']))
        delete_option.click()
        sleep(2)

    #输入选项A、B、C、D
    @classmethod
    def input_options(cls,driver,data):
        optionA = driver.find_element(*eval(cls.element_info['optionA']))
        UIAction.write(optionA,data['optionA'])
        optionB = driver.find_element(*eval(cls.element_info['optionB']))
        UIAction.write(optionB, data['optionB'])
        optionC = driver.find_element(*eval(cls.element_info['optionC']))
        UIAction.write(optionC, data['optionC'])
        optionD = driver.find_element(*eval(cls.element_info['optionD']))
        UIAction.write(optionD, data['optionD'])
        sleep(2)

    #点击正确答案
    @classmethod
    def click_ture_answer(cls,driver):
        ture_answer = driver.find_element(*eval(cls.element_info['ture_answer']))
        ture_answer.click()

    #点击保存按钮
    @classmethod
    def click_scb_save(cls,driver):
        scb_save = driver.find_element(*eval(cls.element_info['scb_save']))
        scb_save.click()

    #断言
    @classmethod
    def click_scb_error(cls,driver):
        if UIAction.is_element_present(*eval(cls.element_info['scb_error'])):
            driver.find_element(*eval(cls.element_info['scb_error'])).click()
            actual = '添加失败'
            driver.refresh()
        else:
            actual = '添加成功'
        return actual

    # 执行
    @classmethod
    def do_single_choice(cls,driver,data):
        cls.element_info = Util.read_ini('choice')
        print(cls.element_info)
        cls.click_single_choice_button(driver)
        cls.select_scb_way(driver)
        cls.select_scb_stage(driver)
        cls.select_scb_class(driver)
        cls.input_topic(driver,data)
        cls.click_add_option(driver)
        cls.click_delete_option(driver)
        cls.input_options(driver,data)
        cls.click_scb_save(driver)
        time.sleep(2)
        return cls.click_scb_error(driver)





class Automatic_question_generation:
    pass

class Exam_paper_records:
    pass